home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Development Platforms / Apple II / Essentials / GSBug / Debug.Tips.1990 next >
Encoding:
Text File  |  1992-07-01  |  10.2 KB  |  224 lines  |  [TEXT/pdos]

  1. Apple IIgs Debugging Tips and Techniques
  2. compiled by David A. Lyons, Apple II Developer Technical Support
  3. July 18, 1990
  4.  
  5. (July 23: corrected "InstallNDA is new for 5.0" to "RemoveNDA is new
  6. for 5.0, and be careful about removing DAs.  Otherwise this document
  7. is what I handed out as the A2-Central Developers Conference.)
  8.  
  9. General Techniques
  10.  
  11. In a Desktop-based program that normally displays the super-hires
  12. graphics screen, write debugging messages to the text screen at
  13. selected points in your program (using the Text Tools, for example).
  14. Then in the event loop, test the mouse position (it appears in the 
  15. "where" field of the event record after a GetNextEvent or TaskMaster 
  16. call).  If the mouse is in the upper left corner of the screen switch
  17. to the text screen using the QuickDraw II call GrafOff.  If the mouse
  18. is anywhere else, switch back to the graphics display with GrafOn. 
  19. (Reported by Ron Lichty; technique by Allan Bell, Australia)
  20.  
  21. Check for errors on all toolbox calls that allocate memory.  Have a
  22. scheme for dealing with low-memory situations.  See Apple IIgs
  23. Technical Notes #51, 52, 56, and others, and read about the System 
  24. Software 5.0 Out Of Memory Queue handling introduced (Apple IIgs
  25. Toolbox Reference Volume 3).
  26.  
  27. Make sure the Bank register is set right.  If you're writing code
  28. that all fits into a single 64K bank, you may want to always keep
  29. your data inside your code segment and use PHK PLB.  If your data
  30. is in a separate segment, this is bad (you may not discover it right
  31. away, because two segments can wind up in the same bank most of the 
  32. time, especially if they happen to be small).
  33.  
  34. Use safety checks possible in your development environment.  For
  35. example, if you use macros to allocate direct-page locations, use
  36. assemble-time error messages to check the amount of direct-page space
  37. you're using.  If it exceeds 256 bytes, complain during assembly; 
  38. this will be a lot more fun than trying to figure out why your code
  39. mysteriously crashes.
  40.  
  41. Watch out for uninitialized storage locations!  Random values may
  42. allow your code to work a lot of the time, so suspect this problem 
  43. especially if your code works right sometimes and fails other times.
  44. (Developer Technical Support provides "Pointer Check" routines for
  45. use with APW C.  See Sample Code volume 2.)
  46.  
  47.  
  48.  
  49. Tips for using GSBug
  50. (Thanks to Tim Swihart for some of these GSBug tips.)
  51.  
  52. Break into your application at a strategic toolbox call, such as 
  53. TaskMaster, by using the GSBug commands SetTBrk and TBrkIn.  When
  54. you hit r to resume your application, you will automatically drop
  55. into GSBug when you hit the selected call.  At that point you can 
  56. disassemble pieces of your code, start single-stepping it with s,
  57. or whatever.   You can usually even hit Apple-Ctrl-ESC to enter your
  58. favorite CDA (see below).
  59.  
  60. Here's a way to trace your program's code for handling a particular
  61. menu item.  Set a tool break on TaskMaster.  Resume your code and let
  62. it break on the TaskMaster call.  Type s to display the super-hires 
  63. screen, and click and hold the mouse button on the menu bar.  Press 
  64. space to execute the TaskMaster call.  Select a menu item and release
  65. the mouse.  At this point, you are still in GSBug, and TaskMaster has
  66. just returned.  Press T to display the text screen, and press space 
  67. to step through your code.
  68.  
  69. Debugging a Classic Desk Accessory is hard, because the stack is
  70. normally in $00/01xx when a CDA executes.  GSBug is not able to 
  71. trace code reliably while the stack pointer is in this range.  
  72. Here's something you can do instead, if you really need to trace 
  73. that CDA code:  break into the application at a convenient point 
  74. (like at a TaskMaster call), set D=0 and start Stepping from the
  75. CDA's entry point (one way to determine the entry point is with
  76. Nifty List--try c018.5000i to find the right block in memory, and 
  77. use ;c to display the name and entry points).
  78.  
  79. Debugging a New Desk Accessory with GSBug was hard in the past,
  80. because the debugger could not receive any keystrokes while an NDA
  81. window was in front.  With GSBug 1.5, just push down the CapsLock 
  82. key, and all is well (the NDA does not receive any keystrokes while
  83. CapsLock is down and GSBug 1.5 is installed.)
  84.  
  85. Type "off" in GSBug to see the top 23 lines of your code's "Real"
  86. text screen.  Type "on" to get the GSBug screen back. 
  87.  
  88. If you get really fancy, you can build the strings (used in the
  89. SetMileStone and DebugStr calls) on the fly and imbed the values 
  90. of key variables into them to further simplify locating the bug.
  91.  
  92. If your development languages supports imbedding names or other 
  93. info about your source into your object, use them.  This helps you
  94. find routines at debug-time.
  95.  
  96.  
  97.  
  98. Nifty List Techniques
  99.  
  100. Nifty List is a Classic Desk Accessory by Dave Lyons.  It's 
  101. Shareware, and you can download it from GEnie or America Online, 
  102. among other places.  If he ever happens to be right in the same room
  103. with you, be sure to ask him for a copy.
  104.  
  105. Here are a few things I do when I'm debugging some code with Nifty
  106. List handy.
  107.  
  108. Pop into Nifty List and type V to see if you've really started up 
  109. all the tools you think you have, and make sure the Work Area 
  110. Pointers are valid (most tools use their WAPs for the address you
  111. pass to the startup routine; the Control Manager is currently an 
  112. exception).  Most of the other tool sets have valid handles or 0 for
  113. their WAPs.  This is not guarnateed, but it's a useful sanity check
  114. while you're writing an application.  (A few tool sets share the same
  115. work areas.  Don't worry; it's normal for the Window Manager and
  116. Event Manager to share, and for QuickDraw II and QuickDraw II 
  117. Auxiliary to share, for example.)
  118.  
  119. Use the new Nifty List 3.0 \addfree and \check commands in Big
  120. Brother module to detect accidental memory stomping.
  121.  
  122. Use c018.1000i to locate the static code segments in your application
  123. ("Info on handles with owner $10xx and memory manager attributes 
  124. $C018").
  125.  
  126. Use 0/0;w to dump info about your window, including the pointer to
  127. the Content Draw routine.  Make sure the content-draw routine does
  128. not assume that the Bank or D registers are set on entry!  If it 
  129. changes them, make sure it puts them back.
  130.  
  131. If your window doesn't update right, check your content draw 
  132. routine--you must not assume you are the frontmost window, so using
  133. FrontWindow to see what window you're supposed to draw in is wrong.
  134. Use GetPort instead, because TaskMaster sets the QuickDraw port to
  135. your window before it calls your update routine.
  136.  
  137. Explore the toolbox by making toolbox calls directly from the Nifty 
  138. List command line.
  139.  
  140.  
  141. When you Crash
  142.  
  143. When you crash, look on the stack for return addresses to see how 
  144. you got there.  Sometimes things went so weird this is impractical,
  145. but it often helps.  Nifty List's ;s command looks for RTS and RTL
  146. addresses for you automatically.  (An "RTL address" is a sequence of
  147. 3 bytes on the stack that is the address of the last byte of a JSL 
  148. instruction your program has executed, but which has not yet
  149. returned.)
  150.  
  151. Check the Direct page register on a crash--by comparing against the 
  152. WAPs for tools, you can often determine which toolset was in control
  153. of the machine when it crashes (that doesn't mean it isn't your 
  154. fault, but it gives you a clue about where to look!). 
  155.  
  156.  
  157.  
  158. Logic Analyzers
  159.  
  160. Logic Analyzers are hardware that hooks up to your computer and
  161. watches what's going on.  They're pretty expensive, and you don't
  162. need one for most debugging problems.  For certain types of problems,
  163. though, they come in very handy.  For example, if you have found a
  164. particular byte of memory that gets changed for no reason, but your 
  165. best efforts to find out what piece of code is actually changing 
  166. that byte have failed, a logic analyzer can help.  (Debugging code
  167. that gets called during interrupts can be impossible to debug with
  168. GSBug.  If you can step through the code outside the interrupt 
  169. environment, great--if that's impossible, consider using a logic 
  170. analyzer.)
  171.  
  172. The general idea is to tell that logic analyzer to "trigger" on a
  173. particular event (a read or write of a particular byte in memory)
  174. and then to record what happens after that (storing everything that 
  175. the processor does, or just selected operations).  This happens
  176. quickly, and then you can scroll through the resulting list to see
  177. exactly what happened in the next thousand or more clock cycles.
  178.  
  179. Trick:  include accesses to known ROM locations to help you trigger
  180. the analyzer at particlar spots in your code (STA $FF0000, $FF0002,
  181. $FF0004, etc).
  182.  
  183.  
  184. Here is some specific information about HP logic analyzers used for
  185. debugging on the Apple II Family.  The HP 16500 provides more 
  186. sophisticated trap specification end specification of which
  187. instructions to store when a trap is in effect.  This provides for
  188. more trace mileage out of the 1024 instructions that can be traced 
  189. than is possible on the HP 1630G, also used at Apple. Also, the 
  190. 16500 works just like the 1650A for a lot of things.
  191.  
  192. You can call the HP Customer Information Center at 1-800-752-0900,
  193. extension779E.  Their catalog says that if they don't have an answer
  194. they'll put you in touch with someone who does.
  195.  
  196. Also, the software for using these analyzers with the 65816 or 65C02
  197. is available direct from us at Apple along with instructions for 
  198. wiring the PODs accordingly. There are a couple of San Francisco 
  199. area companies who rent these machines (see below).
  200.  
  201. If you prefer to rent or lease the models, HP should be able to put
  202. you in contact with a vendor in your area that could do this.
  203. Engineers at Apple using these systems are very happy with them and
  204. generally prefer the touch screen capability of the 16500 model.
  205. (Hey, this isn't an endorsement, it's just information!)
  206.  
  207. Also, an in-circuit emulator for the IIe and IIgs is manfactured by
  208. the Western Design Center, Inc.  At the 1989 A2-Central Apple II
  209. Developer's conference Andrew Hall demonstrated this ICE system,
  210. called the Toolbox Design System, and stated that they would be open 
  211. to rentals of the system.  You can contact The Western Design Center
  212. at 2166 East Brown Rd., Mesa, AZ 85213,  (602) 962-4545.
  213.  
  214. These HP Logic Analyzer units should be rentable through the 
  215. following companies:
  216.  
  217.    Continental Resources       McGrath RentCorp
  218.    1575 McCandless Drive       2500 Grant Avenue
  219.    Milpitas, CA  95035         San Lorenzo, CA  94580
  220.    (408) 263-1775              (415) 276-2626
  221.  
  222. (Thanks to Dan Strnad of DTS for this information on HP logic 
  223. analyzers)
  224.